"""
思路：每个栈位存储数字和截至目前的最小值
缺点：最小值存储存在冗余（如果入栈元素没有变小）
"""

class MinStack:

    def __init__(self):
        """
        initialize your data structure here.
        """
        self.stack = []


    def push(self, x: int) -> None:
        if len(self.stack):
            self.stack.append([x, min(x, self.stack[-1][1])])
        else:
            self.stack.append([x,x])

    def pop(self) -> None:
        self.stack.pop()

    def top(self) -> int:
        return self.stack[-1][0]

    def min(self) -> int:
        return self.stack[-1][1]


# Your MinStack object will be instantiated and called as such:
# obj = MinStack()
# obj.push(x)
# obj.pop()
# param_3 = obj.top()
# param_4 = obj.min()

if __name__ == '__main__':
    minStack = MinStack();
    minStack.push(-2);
    minStack.push(0);
    minStack.push(-3);
    print(minStack.min());   #返回 -3.
    minStack.pop();
    print(minStack.top());   # 返回 0.
    print(minStack.min());   # 返回 -2.